<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天津商务职业学院</title>
</head>
<link href="../static/plugin/layui/css/layui.css" rel="stylesheet"/>
<script type="text/javascript" src="../static/plugin/layui/layui.js"></script>
<script type="text/javascript" src="../static/js/common.js"></script>
<body bgcolor="#8a2be2">
<form class="layui-form layui-form-pane" action="store/updatestore" method="post">
    <input id="id" name="id" type="hidden">
    <div class="layui-form-item" style="margin-top: 15px;margin-left: 30px;">
        <label class="layui-form-label" style="border-radius: 20%;">指标名称</label>
        <div class="layui-input-inline">
            <input type="text" name="indexname" id="indexname" lay-verify="required" placeholder="请输入"
                   autocomplete="off"
                   class="layui-input" style="border-radius: 20%;">
        </div>
        <label class="layui-form-label" style="border-radius: 20%;">权重</label>
        <div class="layui-input-inline">
            <input type="text" name="weight" id="weight" lay-verify="required" placeholder="请输入" autocomplete="off"
                   class="layui-input" style="border-radius: 20%;">
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 15px;margin-left: 30px;">
        <label class="layui-form-label" style="border-radius: 20%;">父指标</label>
        <div class="layui-input-inline">
            <select name="parentId" id="parentId" id="parentId" lay-verify="" style="border-radius: 20%;">

            </select>
        </div>
        <div class="layui-form-mid layui-word-aux" style="border-radius: 20%;">选择无即为父指标</div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block"  align="center">
            <button class="layui-btn" lay-submit="" lay-filter="saveOrAdd" style="border-radius: 20%;">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary" style="border-radius: 20%;">重置</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript">
    layui.use(['form', 'layer', 'table', 'upload'], function () {
        var table = layui.table, $ = layui.$, form = layui.form, upload = layui.upload;
        //编辑时候赋值
        var urlParam = getParam('id');
        $.post("first/selectFir", function (msg) {
            log(msg);
            var html = "<option value=\"\">无</option>";
            for (var i in msg) {
                html = html + "<option value=\""+msg[i].id+"\">"+msg[i].indexname+"</option>"
            }
            $("#parentId").html(html);
            form.render('select');
        });
        if (!isEmpty(urlParam)) {
            $.ajax({
                url: "first/getFirst",
                data: {"id": urlParam},
                type: "POST",
                dataType: "json",
                success: function (msg) {
                    console.log(msg);
                    var json = msg;
                    for (var key in json) {
                        $("#" + key + "").val(json[key]);
                    }
                    form.render('select');
                },
                error: function (error) {
                    layer.msg('系统异常！请联系管理员', {icon: 5});
                }
            });
        }

        //监听编辑或者添加
        form.on('submit(saveOrAdd)', function (data) {
            var url = $("#id").val() == "" ? "first/add" : "first/update";
            var datas = data.field;
            console.log(datas);
            $.ajax({
                url: url,
                data: JSON.stringify(datas),
                type: "POST",
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success: function (msg) {
                    log(msg);
                    if (msg == 1) {
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg('修改成功...', {icon: 6});
                        parent.layer.close(index);
                        window.parent.location.reload();
                    } else {
                        layer.msg('修改失败', {icon: 5});
                    }
                },
                error: function (error) {
                    layer.msg('系统异常！请联系管理员', {icon: 5});
                }
            });
            return false;
        });

    });
</script>
</html>